﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Upeu.Matricula.Data.Entities;

namespace Upeu.Matricula.Data.Business
{
    public class CursoBusiness
    {
        //cambie
        public static IList<Curso> GetList(string filter)
        {

            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                return ctx.Cursos.Where(t => t.Nombrec.Contains(filter)).ToList();
            }
        }
        public static Curso Create(Curso curso)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                Curso cursoDB = ctx.Cursos.Add(curso);
                ctx.SaveChanges();
                return cursoDB;
            }
        }
        public static Curso Update(Curso curso)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                ctx.Entry(curso).State = EntityState.Modified;
                ctx.SaveChanges();
                return curso;
            }
        }
        public static Curso GetById(Guid CursoId)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                Curso c = ctx.Cursos.Find(CursoId);
                if (c == null)
                {
                    throw new Exception("Curso no found in data base.");
                }
                return c;
            }
        }
        public static void Delete(Guid CursoId)
        {
            using (UpeuMatriculaDbContext ctx = new UpeuMatriculaDbContext())
            {
                Curso c = ctx.Cursos.Find(CursoId);
                if (c == null)
                {
                    throw new Exception("Curso no found in data base.");
                }
                ctx.Cursos.Remove(c);
                ctx.SaveChanges();
            }
        }
    }
}